package com.sans.oop;

import org.junit.Test;

/**
 * @author Sans
 */
public class InstanceOfTest {
    static class Fu {
        String name = "父类";

        public String info() {
            return "我是父类...";
        }
    }

    static class Zi extends Fu {
        String name = "子类";

        @Override
        public String info() {
            return "我是子类...";
        }
    }

    @Test
    public void instanceOf() {
        Fu ziA = new Zi();
        System.out.println(ziA.name);
        System.out.println(ziA.info());

        Zi ziB = new Zi();
        Fu fuB = ziB;
        System.out.println(fuB);

        Fu fuC = new Zi();
        Zi ziC = (Zi) fuC;
        System.out.println(fuC);

        System.out.println(ziA instanceof Fu);
        System.out.println(ziA instanceof Zi);
        System.out.println(ziB instanceof Fu);
        System.out.println(ziB instanceof Zi);
    }
}
